<?php
namespace Index\Controller;
use think\Controller;

class IndexController extends Controller{

	public function index(){

		//load about us info / company info
		$abt = M('abtus');
		$getAbt = $abt->find(1);
		$getAbt['contact'] = html_entity_decode($getAbt['contact']);

		//websettings  网页信息配置
		$webset = M('web_settings');
		$getSettings = $webset->find(1);
		$getSettings['web_logo'] = '/Public/Uploads/'.$getSettings['web_logo'];


		//技术页面
		$tec = M('tec_info');
		$getTecInfo = $tec->find(1);


		//banner 聚焦图
        $banner = M('banners');
        $getBanner = $banner->find(1);

        //商品信息
        $g = M('goods');
        $goods = $g->select();
        foreach ($goods as &$k) {
			
			$k['details'] = html_entity_decode($k['details']);  //解码html
		}
       

       //banner 聚焦图
        $t = M('tools');
        $tools_info = $t->find(1);


		$this->assign([
			'getAbt'  =>  $getAbt,  //about us 
			'getSettings'=> $getSettings,  //网站信息配置
			'getTecInfo'=>$getTecInfo,   //技术信息
            'getBanner' => $getBanner,   //banner
            'goods'   =>  $goods,  //商品
            'tools_info' => $tools_info,   //工具
		]);
		$this->display();
	}


	//添加留言
	public function message(){


		$data = I('post.');   //需要添加过滤  htmlspecialchar()
		
		$data['is_show'] = 0;
		$data['create_time'] = date('Y-m-d H:i:s');

		empty($data['name']) && $this->error('Please fill your name.');
		empty($data['email']) && $this->error('Please fill your email.');
		empty($data['comments']) && $this->error('Please don\'t leave blank to us..,say something.');

		$res = M('message')->add($data);
		if($res){
			$this->success('OK, We got your message and will reply you via email soon.^_^ . Thankyou~',U('index'));
		}else{
			$this->error('Sorry, something goes wrong with network, you can just send mail to US. See bellow ^^,  Thank you~~');
		}
	}


}
